#import "XMAlertHelper.h"


@implementation XMAlertHelper
+ (void)alertTitle:(NSString *)title
           message:(NSString *)msg
       cancelTitle:(NSString *)cancelTitle
         sureTitle:(NSString *)sureTitle
      cancelAction:(void (^)(void))cancelAction
        sureAction:(void (^)(void))sureAction {
    UIAlertController *alert = [UIAlertController alertControllerWithTitle:title message:msg preferredStyle:UIAlertControllerStyleAlert];
    if (cancelTitle.length > 0) {
        UIAlertAction *cancel = [UIAlertAction actionWithTitle:cancelTitle
                                                         style:UIAlertActionStyleDefault
                                                       handler:^(UIAlertAction *_Nonnull action) {
                                                           if (cancelAction) {
                                                               cancelAction();
                                                           }
                                                       }];
        [cancel setValue:[UIColor colorWithRed:102 / 255.0 green:102 / 255.0 blue:102 / 255.0 alpha:1.0] forKey:@"titleTextColor"];
        [alert addAction:cancel];
    }
    if (sureTitle.length > 0) {
        UIAlertAction *sure = [UIAlertAction actionWithTitle:sureTitle
                                                       style:UIAlertActionStyleDefault
                                                     handler:^(UIAlertAction *_Nonnull action) {
                                                         if (sureAction) {
                                                             sureAction();
                                                         }
                                                     }];
        [sure setValue:kAppMainColor forKey:@"titleTextColor"];
        [alert addAction:sure];
    }
    if (title.length > 0) {
    }
    if (msg.length > 0) {
    }
    [[UIApplication sharedApplication].keyWindow.rootViewController presentViewController:alert animated:YES completion:nil];
}
@end
